package com.wang.getEnum;

/**
 * @author yandong
 */
import com.wang.getEnum.domain.EnumInfo;
import com.wang.getEnum.scanner.EnumScanner;
import com.wang.getEnum.service.IEnumCacheService;
import jakarta.annotation.Resource;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import java.util.List;

/**
 * 启动时初始化枚举缓存
 * @author yandong
 */
@Component
public class EnumCacheInitializer implements CommandLineRunner {

    @Resource
    private EnumScanner enumScanner;

    @Resource
    private IEnumCacheService enumCacheService;

    @Override
    public void run(String... args) throws Exception {
        // 扫描枚举
        List<EnumInfo> enumInfos = enumScanner.scanEnums();

        // 缓存到Redis
        enumCacheService.setCacheEnums(enumInfos);
        System.out.println("枚举缓存初始化完成，共加载 " + enumInfos.size() + " 个枚举类");
    }

}
